//
//  NIBaseSmsCodeViewController.m
//  AIWAYS
//
//  Created by Marx on 2018/6/13.
//  Copyright © 2018年 wlq. All rights reserved.
//

#import "NIBaseSmsCodeViewController.h"
#import "NITimer.h"

@interface NIBaseSmsCodeViewController ()
{
    
    //以下为timer所需要
    BOOL hasSendSmsCode;
    NITimer *timer;
    dispatch_source_t gcdtimer;
    NSString *leftTimeStr;
}

@end

@implementation NIBaseSmsCodeViewController
- (void)dealloc
{
    [self cancelCountDownTime];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}



#pragma mark - 子类需要重写以下方法以完成功能
-(void)loadGetSmsCodeButtonStatus
{
    
}



#pragma mark - timer

/**
 倒计时
 */
- (void)countDownTimeRightNow:(int)time
{
    if (timer == nil) {
        timer = [[NITimer alloc]init];
    }
    hasSendSmsCode = YES;
    [timer countDownWithTotalTime:time callback:^(BOOL finish, NSString *leftTime, dispatch_source_t gcdTimer) {
        gcdtimer = gcdTimer;
        if (finish) {
            leftTimeStr = nil;
            [self cancelCountDownTime];
        }
        else
        {
            leftTimeStr = leftTime;
        }
        [self loadGetSmsCodeButtonStatus];
        
    }];
    
}


/**
 停止倒计时
 */
- (void)cancelCountDownTime
{
    if (gcdtimer && timer) {
        [timer cancelCountDown:gcdtimer];
    }
    
}

-(BOOL)hasSendSmsCode
{
    return hasSendSmsCode;
}

-(NSString *)getLeftTimeStr
{
    return leftTimeStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
